package com.zlzlib.libnetty.base;

import com.zlzlib.libnetty.util.Util;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;

/**
 * 连接初始化基础类
 *
 * @DateTime: 2021/4/13 15:52
 * @Author zlz
 * @Version 1.0
 */
public abstract class BaseChannelInitializer<T extends Channel> extends ChannelInitializer<T> {

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        Util.logError("异常= " + cause.getMessage());
        super.exceptionCaught(ctx, cause);
    }

    @Override
    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
        Util.logError("助手类添加= " + ctx);
        super.handlerAdded(ctx);
    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
        Util.logError("助手类移除= " + ctx);
        super.handlerRemoved(ctx);
    }

    @Override
    public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
        Util.logError("channel移除了= " + ctx);
        super.channelUnregistered(ctx);
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        Util.logError("channel活跃= " + ctx);
        super.channelActive(ctx);
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        Util.logError("channel不活跃= " + ctx);
        super.channelInactive(ctx);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        Util.logInfo("channel 读取= " + msg);
        super.channelRead(ctx, msg);
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        Util.logInfo("channel 读取完毕= " + ctx);
        super.channelReadComplete(ctx);
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        Util.logInfo("channel 用户事件触发= " + evt);
        super.userEventTriggered(ctx, evt);
    }

    @Override
    public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
        Util.logInfo("channel 可写更改= " + ctx);
        super.channelWritabilityChanged(ctx);
    }
}
